<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <!-- INTERFACE -->
    <cc:interface>
        <cc:attribute name="id" />
        <cc:attribute name="width" />
        <cc:attribute name="height" />
        <cc:attribute name="selectionFor" />
        <cc:attribute name="onselectComplete" />
        <cc:attribute name="titulo" required="true" />
        <cc:attribute name="pageCadastro" />
        <cc:attribute name="pagePesquisa" />
        <cc:attribute name="onselectUpdate" />
        <cc:attribute name="onCloseUpdate" required="true" />
        <cc:attribute name="listaIncluir" />
        <cc:attribute name="closeListener" required="true"
                      method-signature="void method(org.primefaces.event.CloseEvent)" />
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <c:set var="cid" value="#{cc.attrs.id}_widvar" />
        <c:set var="tabWidvar" value="tab#{cc.attrs.id}_widvar" />
        <c:set var="trocarAba" value="#{tabWidvar}.selectTab(0);" />
        <c:set var="fecharModal" value="#{cid}.hide();" />
        <c:set var="onCloseUpdate" value="#{cc.attrs.id}:messages#{!empty cc.attrs.onCloseUpdate ? ',' : ''}#{cc.attrs.onCloseUpdate}" />
        <c:set var="onselectCompleteClose" value="#{!empty cc.attrs.onselectComplete ? onselectComplete : ''}#{!empty cc.attrs.onselectComplete ? ',' : ''}#{!empty cc.attrs.pageCadastro ? trocarAba : fecharModal}" />
        <p:dialog header="#{cc.attrs.titulo}" draggable="false"
                  widgetVar="#{cid}" resizable="false" appendToBody="true"
                  onCloseUpdate="#{onCloseUpdate}" modal="true"
                  closeListener="#{cc.attrs.closeListener}"
                  width="#{!empty cc.attrs.width ? cc.attrs.width : 760}"
                  height="#{!empty cc.attrs.height ? cc.attrs.height : 470}">
            <div id="divMessages">
                <p:messages id="messages" globalOnly="true" showDetail="true" showSummary="false" />
            </div>
            <p:tabView widgetVar="#{tabWidvar}">
                <p:tab title="#{msgs['aba.cadastro']}"
                       rendered="#{!empty cc.attrs.pageCadastro}">
                    <ui:include src="#{cc.attrs.pageCadastro}" parent="#{cc.attrs.id}">
                        <ui:param name="messages" value="#{cc.attrs.id}:messages" />
                        <ui:param name="selection" value="#{cc.attrs.selectionFor}" />
                        <ui:param name="listaIncluir" value="#{cc.attrs.listaIncluir}" />
                        <ui:param name="onselectComplete" value="#{cc.attrs.listaIncluir != null ? cc.attrs.onselectComplete : onselectCompleteClose}" />
                    </ui:include>
                </p:tab>
                <p:tab title="#{msgs['aba.pesquisa']}" rendered="#{!empty cc.attrs.pagePesquisa}">
                    <ui:include src="#{cc.attrs.pagePesquisa}">
                        <ui:param name="showDelete" value="#{!empty cc.attrs.pageCadastro}" />
                        <ui:param name="showIncluir" value="#{cc.attrs.listaIncluir != null}" />
                        <ui:param name="messages" value="#{cc.attrs.id}:messages" />
                        <ui:param name="selection" value="#{cc.attrs.selectionFor}" />
                        <ui:param name="onselectUpdate" value="#{cc.attrs.onselectUpdate}" />
                        <ui:param name="onselectComplete" value="#{onselectCompleteClose}" />
                    </ui:include>
                </p:tab>
            </p:tabView>
        </p:dialog>
    </cc:implementation>
</html>